********************************************************************************
*** activity plots

use "data/pseudodata/userhourlevel_pseudodata.dta", clear

* activity plot of hugo actions
keep if day<=90 & day>=0
keep if bound==1 & daily==1

*organize by cohort and number of days of insurance
bysort id: egen dayscov = sum(hascov)
sort cohort dayscov id hour
gen idfac = id!=id[_n-1]
replace idfac = idfac + 2 if idfac==1 & cohort!=cohort[_n-1] & !mi(cohort[_n-1])
replace idfac = sum(idfac)
bysort cohort: egen firstco = min(idfac)
list cohort firstco if idfac==firstco & hour==0
gen miss=1

*graph
graph twoway	(scatter idfac day if hasres==0 & hascov==0, ///
					msymbol(square) mfcol("68 1 84") mlcol("68 1 84") msize(.21412038 #pt)) ///
				(scatter idfac day if hasres==1, ///
					msymbol(square) mfcol("31 158 137") mlcol("31 158 137") msize(.21412038 #pt)) ///
				(scatter idfac day if hascov==1, ///
					msymbol(square) mfcol("180 222 44") mlcol("180 222 44") msize(.21412038 #pt)) ///
				(scatter idfac day if miss==0, ///
					msymbol(square) mfcol("180 222 44") mlcol("180 222 44") msize(2 #pt)) ///
				(scatter idfac day if miss==0, ///
					msymbol(square) mfcol("31 158 137") mlcol("31 158 137") msize(2 #pt)) ///
				(scatter idfac day if miss==0, ///
					msymbol(square) mfcol("68 1 84") mlcol("68 1 84") msize(2 #pt)), ///
				legend(order(4 "Using Coverage" 5 "Has Coverage" 6 "Has No Coverage") ///
					pos(6) ring(1) col(3)) ///
				xtitle("Days from Take-Up") ytitle("") xlab(0(30)90, nogrid) ///
				ylabel(3 "Base" 37 "Base, Bundle" 74 "High" 116 "High, Bundle" ///
					150 "Low" 199 "Low, Bundle", noticks nogrid)
graph display, xsize(60) ysize(100) scale(0.9)
graph export "output/figures/activity_plot.png", replace height(2000)

